<template>
  <view>
    <view>
      <uni-segmented-control
        :current="current"
        :values="items"
        @clickItem="onClickItem"
        styleType="text"
        style="position: fixed; width: 100%; background-color: white"
      ></uni-segmented-control>
      <view style="height: 60rpx"></view>
      <view class="content">
        <view v-show="current === 0">
          <uni-card
            class="card"
            :is-shadow="false"
            is-full
            v-for="(item, index) in dataList"
            :key="index"
            @click="supply('informationDetails', item)"
          >
            <view>
              <text class="title">{{ item.title }}</text>
            </view>
            <text class="left">来源：{{ item.source }}</text>
            <text class="right">时间：{{ item.publishDate }}</text>
          </uni-card>
        </view>
        <view v-show="current === 1">
          <uni-card
            class="card"
            :is-shadow="false"
            is-full
            v-for="(item, index) in dataList2"
            :key="index"
            @click="supply('informationDetails', item)"
          >
            <view>
              <text class="title">{{ item.title }}</text>
            </view>
            <text class="left">来源：{{ item.source }}</text>
            <text class="right">时间：{{ item.publishDate }}</text>
          </uni-card>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
import { news } from "@/utils/api.js";
export default {
  data() {
    return {
      title: "Hello",
      city: 0,
      value: 0,
      items: ["新闻动态", "地方要闻"],
      current: 0,
      cityList: [
        { value: 0, text: "临沂市" },
        { value: 1, text: "罗庄区" },
        { value: 2, text: "河东区" },
        { value: 3, text: "兰山区" },
      ],
      rangeList: [
        { value: 0, text: "招标公示" },
        { value: 1, text: "中标公示" },
        { value: 2, text: "成交公示" },
      ],
      dataList: [],
      dataList2: [],
      ids: [],
      nowPage: 0,
      city: uni.getStorageSync("nowCity"),
    };
  },
  onLoad(e) {
    this.getPage();
  },
  onReachBottom() {
    this.nowPage++;
    if (this.current == 0) {
      news
        .getPage({
          pnewsTypeId: this.ids.data[0].id,
          newsTypeId: this.ids.data[2].id,
          // areaId: this.city.id,
          // level: this.city.level,
          pageNum: this.nowPage,
          pageSize: 30,
        })
        .then((res) => {
          this.dataList = [...this.dataList, ...res.data.rows];
        });
    } else {
      news
        .getPage({
          pnewsTypeId: this.ids.data[0].id,
          newsTypeId: this.ids.data[1].id,
          // areaId: this.city.id,
          // level: this.city.level,
          pageNum: this.nowPage,
          pageSize: 30,
        })
        .then((res) => {
          this.dataList2 = [...this.dataList2, ...res.data.rows];
        });
    }
  },
  methods: {
    async getPage(e) {
      let res2 = await news.getNewsTypes({});
      this.ids = res2;
      let res = await news.getPage({
        pnewsTypeId: this.ids.data[0].id,
        newsTypeId: this.ids.data[2].id,
        // areaId: this.city.id,
        // level: this.city.level,
        pageNum: 0,
        pageSize: 30,
      });
      this.dataList = res.data.rows;
    },
    supply(e, a) {
      uni.navigateTo({
        url: "/pages/" + e + "/" + e + "?data=" + JSON.stringify(a),
      });
    },
    change(e) {
      console.log("e:", e);
    },
    async onClickItem(e) {
      if (e.currentIndex == 0) {
        let res = await news.getPage({
          pnewsTypeId: this.ids.data[0].id,
          newsTypeId: this.ids.data[2].id,
          // areaId: this.city.id,
          // level: this.city.level,
          pageNum: 0,
          pageSize: 30,
        });
        this.dataList = res.data.rows;
      } else {
        let res = await news.getPage({
          pnewsTypeId: this.ids.data[0].id,
          newsTypeId: this.ids.data[1].id,
          // areaId: this.city.id,
          // level: this.city.level,
          pageNum: 0,
          pageSize: 30,
        });
        this.dataList2 = res.data.rows;
      }

      uni.pageScrollTo({
        scrollTop: 0,
        duration: 0,
      });
      if (this.current != e.currentIndex) {
        this.current = e.currentIndex;
      }
    },
  },
};
</script>

<style scoped lang="less">
.card {
  width: 100%;
}
.title {
  font-size: 15px;
  font-family: PingFang-SC-Bold, PingFang-SC;
  font-weight: bold;
  color: #242424;
  line-height: 21px;
}
.left {
  float: left;
  font-size: 14px;
  font-family: PingFang-SC-Medium, PingFang-SC;
  font-weight: 500;
  color: #a2a2a2;
  line-height: 20px;
}
.right {
  float: right;
  font-size: 13px;
  font-family: PingFang-SC-Medium, PingFang-SC;
  font-weight: 500;
  color: #a2a2a2;
  line-height: 18px;
}
.project-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  .project-info {
    width: 92%;
    margin-top: 20rpx;
    margin-bottom: 20rpx;
    display: flex;
    .info-left {
      image {
        width: 220rpx;
        height: 300rpx;
        border-radius: 10rpx;
      }
    }
    .info-right {
      width: 470rpx;
      margin-left: 8rpx;
      display: flex;
      justify-content: space-around;
      flex-direction: column;
      .project-detail {
        font-size: 28rpx;
        color: #303030;
      }
    }
  }
}
</style>
